package com.example.clublesson01.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

import com.bw.kf.lib_base.entity.PlayCartInfoRecord
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.clublesson01.R

class PlayCartInfoAdapter :
    BaseQuickAdapter<PlayCartInfoRecord, BaseViewHolder>(R.layout.play_cart_info_item) {

    override fun convert(helper: BaseViewHolder, item: PlayCartInfoRecord) {
        try {
            val playCartInfoChildAdapter = PlayCartInfoChildAdapter(item.image.size)
            helper.setText(R.id.paly_cart_info_name_tv, item.model_nickname)
            helper.setText(R.id.play_cart_info_time_tv, item.list_show_time)
            helper.setText(R.id.play_cart_info_content_tv, item.content)
            val play_cart_info_img_rec = helper.getView<RecyclerView>(R.id.play_cart_info_img_rec)
            if (item.image.size ==1){
                play_cart_info_img_rec.layoutManager = LinearLayoutManager(context)
            }else{
                play_cart_info_img_rec.layoutManager = GridLayoutManager(context, 3)
            }
            play_cart_info_img_rec.adapter = playCartInfoChildAdapter
            if (item.image.size<=9){
                playCartInfoChildAdapter.data.addAll(item.image)
            }else {
                for (i in 0 until 8) {
                    playCartInfoChildAdapter.data.add(item.image[i])
                }
            }

        } catch (e: Exception) {

        }
    }
}